package com.itheima.controller;

import com.itheima.manager.UserManager;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    UserManager userManager;

    //查询用户列表
    @GetMapping("/manage/users")
    public ResponseEntity findByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize){
       return userManager.findByPage(pageNum,pageSize);
    }

    //查询用户数据
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findUserInfoById(@PathVariable Long userId){
        return userManager.findUserInfoById(userId);
    }

    //查看动态列表
    @GetMapping("/manage/messages")
    public ResponseEntity findMovementByCondition4Page(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize,
            Integer state,
            Long uid){
        return userManager.findMovementByCondition4Page(uid,state,pageNum,pageSize);
    }

    //查看单个动态
    @GetMapping("/manage/messages/{movementId}")
    public ResponseEntity findMovementById(@PathVariable ObjectId movementId){
        return userManager.findMovementById(movementId);
    }

    //查看动态的评论列表
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findMovementComemntByPage(
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize,
            String messageID){
        return userManager.findMovementComemntByPage(messageID,pageNum,pageSize);
    }

}
